//
//  SettingViewController.swift
//  GifUsage
//
//  Created by han on 2020/12/17.
//  Copyright © 2020 Ting Han. All rights reserved.
//

import UIKit

class SettingViewController: UITableViewController {
    
    var pictureNumber = 5
    var time: TimeInterval = 1.0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    
    @IBOutlet weak var pictureNumberLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    
    @IBAction func dismissAction(_ sender: Any) {
        navigationController?.dismiss(animated: true, completion: nil)
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        if indexPath.row == 0 {
            alertPictureNumber()
        } else if indexPath.row == 1 {
            alertTime()
        }
    }
}


extension SettingViewController {
    func alertPictureNumber() {
        let alert = UIAlertController(title: "设置每秒提取图片数量", message: "应用于视频转gif和livephoto转GIF", preferredStyle: .actionSheet)
        alert.addAction(UIAlertAction(title: "1张", style: .default, handler: { action in
            self.pictureNumberLabel.text = action.title
            self.pictureNumber = 1
        }))
        alert.addAction(UIAlertAction(title: "2张", style: .default, handler: { action in
            self.pictureNumberLabel.text = action.title
            self.pictureNumber = 2
        }))
        alert.addAction(UIAlertAction(title: "5张", style: .default, handler: { action in
            self.pictureNumberLabel.text = action.title
            self.pictureNumber = 5
        }))
        
        alert.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil))
        present(alert, animated: true, completion: nil)
    }
    
    func alertTime() {
        let alert = UIAlertController(title: "设置编辑页速度条最大时间", message: "此设置仅是为了方便编辑页速度条精度调整，并不能作为最终每张图片停留时间", preferredStyle: .actionSheet)
        alert.addAction(UIAlertAction(title: "0.5s", style: .default, handler: { action in
            self.timeLabel.text = action.title
            self.time = 0.5
        }))
        alert.addAction(UIAlertAction(title: "1.0s", style: .default, handler: { action in
            self.timeLabel.text = action.title
            self.time = 1.0
        }))
        alert.addAction(UIAlertAction(title: "2.0s", style: .default, handler: { action in
            self.timeLabel.text = action.title
            self.time = 2.0
        }))
        
        alert.addAction(UIAlertAction(title: "5.0s", style: .default, handler: { action in
            self.timeLabel.text = action.title
            self.time = 5.0
        }))
        
        alert.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil))
        present(alert, animated: true, completion: nil)
    }
}
